package com.lovo;

import com.lovo.servlet.LoginServlet;
import com.lovo.servlet.RegisterServlet;
import org.apache.catalina.Context;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.Wrapper;
import org.apache.catalina.startup.Tomcat;

/**
 * 内置tomcat
 */
public class ApplicationMain {
    public static void main(String[] args) throws LifecycleException {
        // 实例化Tomcat
        Tomcat tomcat = new Tomcat();        
        // 设置Tomcat端口        
         tomcat.setPort(8080);        
        // 引导HTTP引擎        
         tomcat.getConnector();        
         Context ctx = tomcat.addContext("",null);
        // 第二个参数是Servlet名称        
         Wrapper servlet = Tomcat.addServlet(ctx,"RegisterServlet",new RegisterServlet());
        // 启动初始化Servlet        
         servlet.setLoadOnStartup(1);
         //servlet路径
         servlet.addMapping("/register");
        // 第二个参数是Servlet名称
         Wrapper loginservlet = Tomcat.addServlet(ctx,"loginservlet",new LoginServlet());
        // 启动初始化Servlet
        loginservlet.setLoadOnStartup(1);
         //servlet路径
        loginservlet.addMapping("/login");
        // 启动服务器
         tomcat.start();
    }
}
